const {
  formatTime
} = require("../../../utils/util")
const api = require("../../../request/api")
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    packageList: {
      type: Array
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    packageList: [{
      name: "",
      phone_number_after: "",
      phone_nuumber_front: "",
      stations: {
        name: "",
        avatar: "",
        updatedAt: ""
      }
    }]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //扫码取件
    getPackage() {
      wx.scanCode({
        success: async (res) => {
          console.log(res.result)
          // 调用扫码取件接口
          let result = this.getQueryParams(res.result)
          console.log(result)
          let result2 = await api.finishPackage(result.id)
          if (result2.code == 400) {
            wx.showToast({
              title: '取件失败',
            })
          }
          wx.showToast({
            title: '取件成功',
          })
          // 触发刷新
          this.triggerEvent('fresh')
        }
      })
    },
    getQueryParams(url) {
      const regex = /[?&]([^=#]+)=([^&#]*)/g;
      const urlParams = {};
      let match;

      while ((match = regex.exec(url))) {
        urlParams[decodeURIComponent(match[1])] = decodeURIComponent(match[2]);
      }

      return urlParams;
    }
  },

})